package com.wyl.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.UUID;

/**
 * @Description 统一封装公共返回
 * @Author WuYiLong
 * @Date 2022/11/3 15:18
 */
@Data
@ApiModel(value = "responseData")
public class ResponseData<T> {

    @ApiModelProperty(value = "响应状态码")
    private Integer code;
    @ApiModelProperty(value = "响应消息")
    private String msg;
    @ApiModelProperty(value = "响应数据")
    private T data;
    @ApiModelProperty(value = "保留数据")
    private Object reserveData;

    @ApiModelProperty(value = "请求id")
    private String requestId = UUID.randomUUID().toString().replace("-","");

    public ResponseData(){}

    private ResponseData(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResponseData(Integer code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private ResponseData(Integer code, String msg, T data,Object reserveData){
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.reserveData = reserveData;
    }

    public static ResponseData create() {
        return new ResponseData();
    }

    public static ResponseData getSuccess() {
        return new ResponseData(200,"操作成功");
    }

    public static <T> ResponseData getSuccessInstance(T t) {
        return new ResponseData(200,"操作成功",t);
    }

    public static ResponseData getFail() {
        return new ResponseData(-1,"操作失败");
    }

    public static ResponseData getFail(String msg) {
        return new ResponseData(-1,msg);
    }


}
